cap log close
log using "$logs/an-iat-k12vnot.log", replace

use "$data/iat", clear
keep if !mi(k12)
	
// Merge with covariates
merge m:1 countyid using "$data/seda_covariates_clean", keep(3) nogen

// Condition on having all covariates
egen rm = rowmiss(implicitbias amind eastasian southasian nathaw black blackwhite multiother otherun female agecat ed schoolyear ///
	sesall ///
	perblk perhsp /*pctenglish1*/ hswhtblk hsflnfl percharter_all ///
	ppexp_inst stutch_all ///
	flunchwhtblk percharterwhtblk stutchwhtblk seswhtblk)
keep if rm == 0
drop rm

est clear

// Models...

eststo: mixed implicitbias ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-k12vnot.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 
	   
eststo: mixed implicitbias k12 ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-k12vnot.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 
	   
	   
	   
eststo: mixed implicitbias k12 ///
	amind eastasian southasian nathaw black blackwhite multiother otherun ///
	female i.agecat i.ed ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-k12vnot.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 
	
eststo: mixed implicitbias k12 ///
	sesall ///
	perblk perhsp /*pctenglish1*/ hswhtblk hsflnfl percharter_all ///
	ppexp_inst stutch_all ///
	flunchwhtblk percharterwhtblk stutchwhtblk seswhtblk ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-k12vnot.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 								
		
eststo: mixed implicitbias k12 ///
	amind eastasian southasian nathaw black blackwhite multiother otherun ///
	female i.agecat i.ed ///
	sesall ///
	perblk perhsp /*pctenglish1*/ hswhtblk hsflnfl percharter_all ///
	ppexp_inst stutch_all ///
	flunchwhtblk percharterwhtblk stutchwhtblk seswhtblk ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-k12vnot.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 		
		
log close
